package com.letwal.cmcvnd.anetwork

import com.letwal.cmcvnd.utils.IpUtil
import com.letwal.cmcvnd.utils.UserStateUtil
import java.util.*
import kotlin.collections.HashMap

class ApiHeaderMap : HashMap<String, String>() {

    companion object {
        /** token key */
        const val KEY_TOKEN = "Authorization"
    }

    init {
        put(KEY_TOKEN, UserStateUtil.mToken)

        // 额外拦截字段
        put("ip", IpUtil.ipInfo?.ip ?: "")
        put("city", IpUtil.ipInfo?.city ?: "")
        put("region", IpUtil.ipInfo?.region ?: "")
        put("country", IpUtil.ipInfo?.country ?: "")
        put("loc", IpUtil.ipInfo?.loc ?: "")
        put("org", IpUtil.ipInfo?.org ?: "")

        val timeZoneId = TimeZone.getDefault().id.toString() ?: ""
        val cTz = IpUtil.ipInfo?.timezone ?: ""
        if (cTz.isBlank()) {
            put("timezone", timeZoneId)
        } else {
            put("timezone", cTz)
        }

        put("tz", timeZoneId ?: "")

        println("======= headers:")
        println(this)
    }
}